package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author atguigu-mqx
 */
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    //  /admin/product/baseTrademark/{page}/{limit}
    @GetMapping("{page}/{limit}")
    public Result getBaseTrademark(@PathVariable Long page,
                                    @PathVariable Long limit){
        //  mybatis-plus 有分页类！
        //  创建一个Page 对象
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page,limit);
        //  sql ......
        IPage iPage = baseTrademarkService.getBaseTrademark(baseTrademarkPage);
        return Result.ok(iPage);

    }

    //  /admin/product/baseTrademark/save
    //  保存 json --> Java Object
    @PostMapping("save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        //  调用保存方法！
        baseTrademarkService.save(baseTrademark);
        //  默认返回
        return Result.ok();
    }

    //  /admin/product/baseTrademark/remove/{id}
    @DeleteMapping("remove/{id}")
    public Result removeById(@PathVariable Long id){
        //  调用服务层方法
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    //  回显数据：/admin/product/baseTrademark/get/{id}
    @GetMapping("get/{id}")
    public Result getById(@PathVariable Long id){
        //  调用服务层方法
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    //  /admin/product/baseTrademark/update
    @PutMapping("update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        //  修改数据！
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }


    //  /admin/product/baseCategoryTrademark/findTrademarkList/{category3Id}
    //  @GetMapping("findTrademarkList/{category3Id}")


}
